//
//  CaseViewController.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/15.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "CaseViewController.h"
#import "CaseView.h"
@interface CaseViewController ()
@property(nonatomic,strong)CaseView *aView;

@end

@implementation CaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"案件";
    _aView=[CaseView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    [_aView creatView];
    _aView.viewController=self;
    
    UIButton* leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 30, 40);
    [leftBtn setImage:[UIImage imageNamed:@"在线客服"] forState:UIControlStateNormal];
    [leftBtn setTitle:@"客服" forState:0];
    [leftBtn setTitleColor:_backgroundColor forState:0];
    leftBtn.titleLabel.font=[UIFont systemFontOfSize:12];
    leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(- (leftBtn.frame.size.height - leftBtn.titleLabel.frame.size.height- leftBtn.titleLabel.frame.origin.y),(leftBtn.frame.size.width -leftBtn.titleLabel.frame.size.width) -leftBtn.imageView.frame.size.width, 0, 0);
    leftBtn.titleEdgeInsets = UIEdgeInsetsMake(leftBtn.frame.size.height-leftBtn.imageView.frame.size.height-leftBtn.imageView.frame.origin.y, -leftBtn.imageView.frame.size.width, 0, 0);
//    [self initButton:leftBtn];
    
    UIBarButtonItem* leftBtnItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    [leftBtn addTarget:self action:@selector(setviewinfo) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem setRightBarButtonItem:leftBtnItem];
}
-(void)setviewinfo{
    self.navigationItem.rightBarButtonItem.enabled=NO;
    [ZQTools AFNPostDataUrl:@"api/index/get_service_phone" Dict:nil andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        self.navigationItem.rightBarButtonItem.enabled=YES;
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",responseObject];
        UIWebView * callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];  
        
    } anderrorBlock:nil];
}


-(void)initButton:(UIButton*)btn{
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height ,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,0.0, -btn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
